package com.Web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import util.DateUtil;

import com.Dao.ProjectDao;

import com.Dao.employeeProjectSavaDao;
import com.entity.Employee;
import com.entity.Project;
import com.entity.employProject;

public class saveNewFile extends HttpServlet {

	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest requset,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = requset.getSession();

		Employee em = (Employee) session.getAttribute("em");

		String Pname = requset.getParameter("projectname");
		String area = requset.getParameter("textarea");

		employeeProjectSavaDao epdao = new employeeProjectSavaDao();
		employProject ep = new employProject();
		ProjectDao dao = new ProjectDao();
		Project p = new Project();

		p.setName(Pname);
		p.setDesc(area);
		p.setCreatetime(DateUtil.getNow());
		
		int id = dao.save(p);
		
		ep.setEmployeeid(em.getId());
		ep.setProjectid(id);
		epdao.save(ep);

		session.setAttribute("p", p);
		requset.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(
				requset, response);
	}
}
